class Person {
  readonly name: string
  age?:number
  readonly friend?:Person
  //1. 只读属性是可以在构造器中赋值，复制之后就不可以修改
  constructor(name: string, friend?:Person) {
    this.name = name
    this.friend = friend
  }
}

const p = new Person("yzh", new Person("kobe"));
console.log(p.name);
// p.name = "1111"   readonly不可以再次修改

if (p.friend) {
  p.friend.age = 30
}

console.log(p.friend);
//p.friend = new Person("james") //也是不可以直接修改friend

